package com.jhhc.Weathers.datasupplement.util;


import com.jhhc.Weathers.datasupplement.entity.jcdzBO.ProductF;
import org.springframework.stereotype.Component;

import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;

/**
 * @author LYQ
 */
@Component
public class StructureTime {

    public static ProductF ybTimes(String dataType){
        DecimalFormat format = new DecimalFormat("00");
        Calendar calendar = Calendar.getInstance();
        ProductF p = new ProductF();
        //补录代码
//        SimpleDateFormat format1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//        String t = "2024-01-30 00:00:00";
//        try {
//            calendar.setTime(format1.parse(t));
//        } catch (ParseException e) {
//            throw new RuntimeException(e);
//        }
        int year = calendar.get(Calendar.YEAR);
        int m = calendar.get(Calendar.MONTH) + 1;
        int d = calendar.get(Calendar.DATE);
        String month = format.format(m);
        String day = format.format(d);
        List<String> ybTimes = new ArrayList<>();
        switch (dataType){
            case "08-08":
                p.setQbTime(year + month + day + "080000");
                for (int i = 0; i < 3; i++) {
                    calendar.add(Calendar.DATE,1);
                    year = calendar.get(Calendar.YEAR);
                    m = calendar.get(Calendar.MONTH) + 1;
                    d = calendar.get(Calendar.DATE);
                    month = format.format(m);
                    day = format.format(d);
                    ybTimes.add(year + month + day + "080000");
                }
                p.setYbTime(ybTimes);
                break;
            case "20-20":
                p.setQbTime(year + month + day + "200000");
                for (int i = 0; i < 3; i++) {
                    calendar.add(Calendar.DATE,1);
                    year = calendar.get(Calendar.YEAR);
                    m = calendar.get(Calendar.MONTH) + 1;
                    d = calendar.get(Calendar.DATE);
                    month = format.format(m);
                    day = format.format(d);
                    ybTimes.add(year + month + day + "200000");
                }
                p.setYbTime(ybTimes);
                break;
            default:
                break;
        }
        return p;
    }
    /**
     * 时间构造
     * @param ybtime 预报时间yyyyMMddHH0000格式 20230711080000
     * @return yyyy-MM-dd HH:mm:ss格式时间 2023-07-11 08:00:00
     */
    public static String timeConstruction(String ybtime){
        String year = ybtime.substring(0,4);
        String month = ybtime.substring(4,6);
        String day = ybtime.substring(6,8);
        String hour = ybtime.substring(8,10);
        return year + "-" + month + "-" + day + " " + hour + ":00:00";
    }
}
